<template>
	<view>
		<view class="search-box">
			<my-search @click="goSearch"></my-search>
		</view>
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
			<!-- 渲染item项目 -->
			<swiper-item v-for="(item, index) in swiperList" :key="index">
				<navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id=' + item.goods_id"><image :src="item.image_src"></image></navigator>
			</swiper-item>
		</swiper>
		<!-- 第二个部分  -->
		<view class="nav-list">
			<view class="nav-item" v-for="(item, index) in navList" :key="index" @click="navClickHander(item)"><image :src="item.image_src" class="nav-image"></image></view>
		</view>
		<!-- floorList 楼层 -->
		<view class="floor-list">
			<view class="floor-item" v-for="(item, index) in floorList" :key="index">
				<!-- 楼层标题 -->
					<image :src="item.floor_title.image_src" class="floor-title"></image>
				<!-- 图片区域 -->
				<view class="floor-img-box">
					<navigator class="left-img-box" :url="item.product_list[0].url">
						<image :src="item.product_list[0].image_src" 
						:style="{ width: item.product_list[0].image_width + 'rpx' }" mode="widthFix"></image></navigator>
					<view class="right-img-box">
						<navigator :url="item2.url"  class="right-img-item" v-for="(item2, index2) in item.product_list" :key="index2" v-if="index2 !== 0">
							<image :src="item2.image_src" mode="widthFix" 
							:style="{ width: item2.image_width + 'rpx' }"></image>
						</navigator>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			// 轮播图的数据
			swiperList: [],
			// 分类导航数据列表
			navList: [],
			// 楼层数据
			floorList: []
		};
	},
	onLoad() {
		this.getSwiperList();
		this.getNavList();
		this.getFloorList();
	},
	methods: {
		// 轮播图的请求 1 发送 2 结果 3判断 4 清空数据
		async getSwiperList() {
			const { data: res } = await uni.$http.get('/api/public/v1/home/swiperdata');
			if (res.meta.status !== 200) {
				// uni.showToast({
				// 	title: '数据加载失败...',
				// 	icon: 'none',
				// 	duration: 1500
				// });
				uni.$showMsg();
				return (this.swiperList = []);
			} else {
				this.swiperList = res.message;
			}
		},
		async getNavList() {
			const { data: res } = await uni.$http.get('/api/public/v1/home/catitems');
			// console.log('r',res);
			if (res.meta.status !== 200) return uni.$showMsg();
			this.navList = res.message;
		},
		// 跳转tabbar页面
		navClickHander(item) {
			if (item.name === '分类') {
				uni.switchTab({
					url: '/pages/cate/cate'
				});
			}
		},
		async getFloorList() {
			const { data: res } = await uni.$http.get('/api/public/v1/home/floordata');
			// console.log(res);
			if (res.meta.status !== 200) return uni.$showMsg();
			res.message.forEach(floor=>{
				// console.log(floor);
				floor.product_list.forEach(prod=>{
					// console.log(prod.navigator_url.split('?')[1]);
					prod.url='/subpkg/goods_list/goods_list?'+prod.navigator_url.split('?')[1]
					// console.log(prod.url);
				})
			})
			// res.message.forEach(floor => {
			//   floor.product_list.forEach(prod => {
			//     prod.url = '/subpkg/goods_list/goods_list?' + prod.navigator_url.split('?')[1]
			//   })
			// })
			this.floorList = res.message;
		},
		goSearch(){
			uni.navigateTo({
				url:'/subpkg/search/search'
			})
		}
	}
};
</script>

<style lang="scss" scoped>
swiper {
	height: 330rpx;
	.swiper-item,
	image {
		height: 100%;
		width: 100%;
	}
}
.search-box{
	// display: flex;
	// display: str;
	position: sticky;
	top: 0;
	z-index: 999;
}
.nav-list {
	display: flex;
	justify-content: space-around;
	margin: 15rpx 0;
	.nav-image {
		width: 128rpx;
		height: 140rpx;
	}
}
.floor-list {
	.floor-title {
		display: flex;
		height: 60rpx;
		width: 100%;
	}
	.floor-img-box{
		display: flex;
		padding-left: 10rpx;
		.right-img-box{
			display: flex;
			
			flex-wrap: wrap;
			justify-content: space-around;
		}
	}
}
</style>
